import { DataTypes, UUIDV4 } from 'sequelize';

import { getSequelize, MySqlModel } from '../db';

// 参数
class AppParameterNames extends MySqlModel {

}

AppParameterNames.init({
  id: {
    type: DataTypes.STRING(80), unique: 'id', allowNull: false, primaryKey: true, comment: '参数内部名称'
  },
  name: {
    type: DataTypes.STRING(200), unique: 'name', allowNull: false, comment: '参数显示的名字'
  },
  description: {
    type: DataTypes.STRING(200), allowNull: true, comment: '参数描述'
  },
  level: {
    type: DataTypes.STRING(50),
    allowNull: false,
    comment: '参数级别',
    validate: {
      isIn: [['Platform', 'Hotel']]
    }
  },
  sequence: {
    type: DataTypes.INTEGER, allowNull: true, defaultValue: null, validate: { min: 0, max: 999999 }, comment: '排序', logger: true
  },
  created_id: {
    type: DataTypes.UUID, allowNull: false, validate: { isUUID: 4 }, comment: '创建用户'
  },
  updated_id: {
    type: DataTypes.UUID, allowNull: false, validate: { isUUID: 4 }, comment: '更新用户'
  },
  version: {
    type: DataTypes.INTEGER, allowNull: false, defaultValue: 0, comment: '版本控制'
  }
}, {
  sequelize: getSequelize(),
  tableName: 'app_parameter_names',
  comment: '应用参数名称'
});

AppParameterNames.associate = (models) => {
  AppParameterNames.hasMany(models.AppParameterValues, {
    foreignKey: 'app_parameter_name_id',
    sourceKey: 'id',
    alias: 'app_parameter_name'
  });
};

export default AppParameterNames;
